package com.getpebble.android.framework.protocol.outbound;

import com.getpebble.android.framework.protocol.EndpointId;
import com.getpebble.android.framework.util.ByteUtils;

public class PblOutboundNotificationMessage extends PblOutboundMessage {
    private String mBody;
    private String mSender;
    private String mSubject;
    private String mTimestamp;
    private NotificationType mType;

    public enum NotificationType {
        EMAIL((byte) 0),
        SMS((byte) 1),
        FACEBOOK((byte) 2),
        TWITTER((byte) 3);
        
        private final byte id;

        private NotificationType(byte id) {
            this.id = id;
        }

        public byte getId() {
            return this.id;
        }
    }

    private PblOutboundNotificationMessage(NotificationType type, String sender, String body, String timestamp, String subject) {
        super(EndpointId.NOTIFICATION);
        this.mType = type;
        this.mSender = sender;
        this.mBody = body;
        this.mTimestamp = timestamp;
        this.mSubject = subject;
    }

    public static PblOutboundNotificationMessage createSmsNotification(String sender, String body, String timestamp) {
        return new PblOutboundNotificationMessage(NotificationType.SMS, sender, body, timestamp, null);
    }

    public synchronized byte[] getBytes() {
        if (!areBytesCached()) {
            addBytes(Byte.valueOf(this.mType.getId()));
            ByteUtils.writePascalString(this, this.mSender);
            ByteUtils.writePascalString(this, this.mBody);
            ByteUtils.writePascalString(this, this.mTimestamp);
            if (this.mType.equals(NotificationType.EMAIL)) {
                ByteUtils.writePascalString(this, this.mSubject);
            }
        }
        return super.getBytes();
    }
}
